package javaproject;

import java.sql.Statement;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.util.Properties;

public class DBDriver {

	public Connection getConn(){
		Connection conn = null;
		try{
			InputStream is = this.getClass().getClassLoader().getResourceAsStream("db.properties");
			Properties prop = new Properties();
			prop.load(is);
			String dbDriverType = prop.getProperty("dbDriverType");
			String dbURL = prop.getProperty("dbURL");
			String dbUser = prop.getProperty("dbUser");
			String dbPSW = prop.getProperty("dbPSW");
			Class.forName(dbDriverType).newInstance();
			conn = DriverManager.getConnection(dbURL, dbUser, dbPSW);
		}catch (Exception e) {
			// TODO: handle exception
			System.out.println("连接oracle失败-创建异常");
			e.printStackTrace();
		}
		return conn;
	}
	public ResultSet query(String strSql){
		ResultSet rs = null;
		try{
			Statement st = getConn().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
			rs = st.executeQuery(strSql);
		}catch (Exception e) {
			// TODO: handle exception
			System.out.println("oracle-jdbc-数据库查询操作异常：");
			e.printStackTrace();
		}
		return rs;
		
	}
	public void closeConn(Connection conn){
		try{
			if(conn!=null){
				conn.close();
			}
		}catch (Exception e) {
			// TODO: handle exception
			System.out.println("ORALCE-JDBC 数据传输关闭异常");
			e.printStackTrace();
		}
	}
}
